package com.cxs.enums;

import com.cxs.entity.vo.ReservationMarkVO;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ReservationMarkEnums
 * @description:
 * @author: 诗涵
 * @create: 2024-01-07 08:17
 */
public enum ReservationMarkEnums {

    SEAT_6_8("6-8", 6, 8, "6:00-8:00"),
    SEAT_8_10("8-10", 8, 10, "8:00-10:00"),
    SEAT_10_12("10-12", 10, 12, "10:00-12:00"),
    SEAT_12_14("12-14", 12, 14, "12:00-14:00"),
    SEAT_14_16("14-16", 14, 16, "14:00-16:00"),
    SEAT_16_18("16-18", 16, 18, "16:00-18:00"),
    SEAT_18_20("18-20", 18, 20, "18:00-20:00"),
    SEAT_20_22("20-22", 20, 22, "20:00-22:00"),
    ;

    @Setter
    @Getter
    private String mark;

    @Setter
    @Getter
    private Integer startTime;

    @Setter
    @Getter
    private Integer endTime;

    @Setter
    @Getter
    private String timeRange;

    ReservationMarkEnums(String mark, Integer startTime, Integer endTime, String timeRange) {
        this.mark = mark;
        this.startTime = startTime;
        this.endTime = endTime;
        this.timeRange = timeRange;
    }

    public static List<ReservationMarkVO> getReservationMarkVOList(){
        List<ReservationMarkVO> list = new ArrayList<>();
        ReservationMarkEnums[] values = ReservationMarkEnums.values();
        for (ReservationMarkEnums value : values) {
            ReservationMarkVO vo = new ReservationMarkVO();
            vo.setMark(value.getMark());
            vo.setEndTime(value.getEndTime());
            vo.setStartTime(value.getStartTime());
            vo.setTimeRange(value.getTimeRange());
            list.add(vo);
        }
        return list;
    }

    public static ReservationMarkVO getReservationMarkVOByMark(String mark){
        ReservationMarkEnums[] values = ReservationMarkEnums.values();
        for (ReservationMarkEnums value : values) {
            if (value.getMark().equals(mark)) {
                ReservationMarkVO vo = new ReservationMarkVO();
                vo.setMark(value.getMark());
                vo.setEndTime(value.getEndTime());
                vo.setStartTime(value.getStartTime());
                vo.setTimeRange(value.getTimeRange());
                return vo;
            }
        }
        return null;
    }


    public static List<ReservationMarkVO> getReservationMarkVOList(Integer start, Integer end){
        List<ReservationMarkVO> list = new ArrayList<>();
        if (start >= end) {
            return list;
        }
        ReservationMarkEnums[] values = ReservationMarkEnums.values();
        Integer step = 2;
        Integer temp = 0;
        while (true) {
            temp = start+step;
            if (temp >= end) {
                temp = end;
                ReservationMarkVO vo = new ReservationMarkVO();
                vo.setMark(getMarkStr(start, temp));
                vo.setEndTime(temp);
                vo.setStartTime(start);
                vo.setTimeRange(getTimeRangeStr(start, temp));
                list.add(vo);
                break;
            }
            ReservationMarkVO vo = new ReservationMarkVO();
            vo.setMark(getMarkStr(start, temp));
            vo.setEndTime(temp);
            vo.setStartTime(start);
            vo.setTimeRange(getTimeRangeStr(start, temp));
            list.add(vo);
            start = temp;
        }
        return list;
    }

    private static String getTimeRangeStr(Integer start, Integer temp) {
        StringBuilder sb = new StringBuilder();
        sb.append(start)
                .append(":00")
                .append("-")
                .append(temp)
                .append(":00");
        return sb.toString();
    }

    private static String getMarkStr(Integer start, Integer temp) {
        StringBuilder sb = new StringBuilder();
        sb.append(start)
                .append("-")
                .append(temp);
        return sb.toString();
    }

    public static void main(String[] args) {
        List<ReservationMarkVO> reservationMarkVOList = getReservationMarkVOList(6, 21);
        System.out.println(reservationMarkVOList);
    }
}
